package
{
	import org.flixel.*;

	public class Arrow extends FlxSprite
	{
		protected var img:Class;
		private var clicked:Boolean;
		private var orientation:int;
	
		public var associatedEarth:Boolean;
		public var associatedLight:Boolean;
		public var associatedWater:Boolean;
		public var associatedWind:Boolean;
		
		public function Arrow(_x:int, _y:int, direction:int)
		{
			super(_x, _y, null);
			img = Res.BeamArrow;
			switch(direction) {
				case Direction.NORTH:
					angle = 0;
					break;
				case Direction.SOUTH:
					angle = 180;
					break;
				case Direction.WEST:
					angle = 270;
					break;
				case Direction.EAST:
					angle = 90;
					break;
				default:
					break;
			}
			this.orientation = direction;
			loadGraphic(img);
			clicked = false;
			associatedEarth = false;
			associatedLight = false;
			associatedWater = false;
			associatedWind = false;
		}
		
		
		public override function update():void
		{
			super.update();

			//indicate if this arrow is being dragged, thanks Mai
			if (FlxG.mouse.justPressed() && this.overlapsPoint(FlxG.mouse.screenX,FlxG.mouse.screenY)) {
				clicked = true;
			}
			if (FlxG.mouse.justReleased() && clicked) {
				clicked = false;
			}
		}
		
		public function isAssociatedWith(element:int):Boolean {
			if (element == Elemental.EARTH && associatedEarth) {
				return true;
			} else if (element == Elemental.WATER && associatedWater) {
				return true;
			} else if (element == Elemental.WIND && associatedWind) {
				return true;
			} else if (element == Elemental.LIGHT && associatedLight) {
				return true;
			} else {
				return false;
			}
		}
		
		public function setAssociation(element:int):void {
			if (element == Elemental.EARTH) {
				associatedEarth = true;
			} else if (element == Elemental.WATER) {
				associatedWater = true;
			} else if (element == Elemental.WIND) {
				associatedWind = true;
			} else if (element == Elemental.LIGHT && associatedLight) {
				associatedLight = true;
			}
		}
		
		public function clearAssociations():void {
			associatedEarth = false;
			associatedWater = false;
			associatedWind = false;
			associatedLight = false;
		}
		
		public function isClicked():Boolean{
			return clicked;
		}
		
		public function getOrientation():int{
			return orientation;
		}
	}
}